﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ColorMapSystem.Helper
{
    public class ParseHelper
    {

        public static List<List<string>> ParseTmaFile(string filePath, int headerLines)
        {
            List<List<string>> result = new();
            using var reader = new StreamReader(filePath);
            for (int i = 0; i < headerLines; i++) reader.ReadLine();
            string line;
            while ((line = reader.ReadLine()!) != null && line.Contains("|"))
            {
                var row = new List<string>();

                line = line[4..];
                for (int i = 0; i < line.Length; i += 3)
                {
                    string val = line.Substring(i, 3); // 每4位取前2位是数据
                    row.Add(val);
                }

                result.Add(row);
            }
            return result;
        }


        public static List<List<string>> ParseTmbFile(string filePath, int headerLines)
        {
            List<List<string>> result = new();
            using var reader = new StreamReader(filePath);
            for (int i = 0; i < headerLines; i++) reader.ReadLine();
            string line;
            while ((line = reader.ReadLine()!) != null && line.Contains("|"))
            {
                string data = line.Substring(4); // 跳过前缀 "001|"
                var row = new List<string>();

                for (int i = 0; i < data.Length; i += 3)
                {

                    string val = data.Substring(i, 3); // 每4位取前2位是数据
                    row.Add(val);
                }

                result.Add(row);

            }
            return result;
        }


    }
}
